package com.cyou.qb.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class SpringMvcUtils {
	
	
	public static UserContext getUserContext(){
		
		//如果不是http产生的，那么请求就是后台任务
		if(RequestContextHolder.getRequestAttributes()==null||((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest()==null){
			return AdminUserContext.getDefault4Task();
		}
		//FIXME
		return (UserContext) getSession().getAttribute("loginedUser");
	}
	
	public static HttpServletRequest getRequest(){
		return  ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}

	
	public static HttpSession getSession(){
		return getRequest().getSession();
	}
	
}
